//
// Created by 11510 on 2024/6/8.
//
#include <iostream>

using std::cin;
using std::cout;
using std::endl;

void inputInt(int& number){
    cout << "please input a number:" << endl;

//    逗号表达式，右表达式为值
    while(cin >> number , !cin.eof()){
        if(cin.bad()){
            cout << "cin has broken!" << endl;
            return ;
        }else if(cin.fail()){
            cin.clear();
            cin.ignore(0x7fffffffffffffff, '\n');

            cout << "please input a legal number!!!:" << endl;
            cin >> number;
        }else{
//            正常输入的情况
            cout << "num : " << number << endl;
            break;
        }
    }
}

void test0(){
    // system("");
    int num = 0;
    inputInt(num);
}

void test1(){
    int num = 0;

    cin >> num;
    if(cin){/* 流对象goodbit状态时代表true*/
        cout << "hello" << endl;
    }
}

void test2(){
    int num1 = 0, num2 = 2;

    /***
     * 使用cin，cout去进行输入或输出
     * 表达式的返回值就是cin(cout)对象
     * 输入流默认分隔符: \n, \t, 空格
     */
    (cin >> num1) >> num2;
    (cout << "num1 : ") << num1 << endl;
    cout << "num2 : " << num2 << endl;
}


int main() {
    test2();
    return 0;
}